<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .box {
            width: 300px;
            height: 300px;
            background-color: pink;
            margin: 100px;
        }
    </style>
    <script>
        window.addEventListener('load', function() {
            var box = document.querySelector('.box')
            box.addEventListener('mousemove', function(e) {
                var x = e.pageX - box.offsetLeft;
                var y = e.pageY - box.offsetTop;
                box.innerHTML = '鼠标在盒子中的坐标：(' + x + ',' + y + ')'
                    // console.log('鼠标在盒子中的坐标：(' + x + ',' + y + ')');
            })
        })
    </script>
</head>

<body>
    <div class="box"></div>
</body>

</html>